﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using GatewayInspect.Common;
using System.Data.OracleClient;

namespace GatewayInspect.Modules
{
    public partial class FCZLSXDJKModule : BaseModule
    {
        //输入key之后，返回的关键词
        List<string> listNew = new List<string>();

        public FCZLSXDJKModule()
        {
            InitializeComponent();
        }

        protected override void OnInitialize()
        {
            base.OnInitialize();
            foreach (ToolStripItem item in this.tsMain.Items)
            {
                if (item != tsBtnRefresh && item != tsBtnClose && item != toolStripSeparator3)
                {
                    item.Visible = false;
                }
            }
        }

        protected override void OnInit()
        {
            base.OnInit();
        }
        private void CheckData(){
            string strSql = "select PLAN_NO,DRIVER_PHONE,ESCORT_PHONE,HEAD_CAR_NO,PRINT_TIME,IN_PARK_TIME,TRUE_INPARK_TIME,decode(CAR_TYPE, '0','货主自有','1','货主挂靠','2','车队自有','3','车队挂靠') CAR_TYPE,decode(PARK_CODE,'11','平安停车场1','12','平安停车场2','13','平安停车场3','15','安顺停车场1','16','安顺停车场2','17','董家口停车场','18','摩科瑞停车场','23','金赛物流停车场') PARK_NAME " +
                " from VI_DBC_OIL_BILL_PARK_IN where PLAN_NO IS NOT NULL ";
            if (!string.IsNullOrWhiteSpace(comboBox1.Text))
            {
                strSql += " and PLAN_NO like '%" + comboBox1.Text + "%'";
            }

            else if (Session.CurrentUserName == "ADMIN_DJK" || Session.CurrentUserName == "ADMIN")
            {
                strSql += " and (PARK_CODE = '17' OR PARK_CODE = '18')";
            }
            else if (Session.CurrentOrgType == 0)
            {
                strSql += " and PARK_CODE = '" + Session.CurrentOrgCode + "'";
            }

            strSql += " order by VI_DBC_OIL_BILL_PARK_IN.CAR_TYPE,IN_PARK_TIME ,print_time asc";
            DataTable dt = DataAccess.ExecuteDataTable(strSql);

            this.cdgvInOutGate.AutoGenerateColumns = false;
            this.cdgvInOutGate.DataSource = dt;
        }
        private void CheckAllData()
        {
            string strSql = "select PLAN_NO,DRIVER_PHONE,ESCORT_PHONE,HEAD_CAR_NO,PRINT_TIME,IN_PARK_TIME,TRUE_INPARK_TIME,decode(CAR_TYPE, '0','货主自有','1','货主挂靠','2','车队自有','3','车队挂靠') CAR_TYPE,decode(PARK_CODE,'11','平安停车场1','12','平安停车场2','13','平安停车场3','15','安顺停车场1','16','安顺停车场2','17','董家口停车场','18','摩科瑞停车场','23','金赛物流停车场') PARK_NAME " +
                " from VI_DBC_OIL_BILL_PARK_IN where PLAN_NO IS NOT NULL ";
            if (!string.IsNullOrWhiteSpace(comboBox1.Text))
            {
                strSql += " and PLAN_NO like '%" + comboBox1.Text + "%'";
            }

            strSql += " and (PARK_CODE = '17' OR PARK_CODE = '18') order by VI_DBC_OIL_BILL_PARK_IN.CAR_TYPE,IN_PARK_TIME ,print_time asc";
            DataTable dt = DataAccess.ExecuteDataTable(strSql);

            this.cdgvInOutGate.AutoGenerateColumns = false;
            this.cdgvInOutGate.DataSource = dt;
        }
        protected override void OnLoadModule()
        {
            base.OnLoadModule();
             //清空combobox
            this.comboBox1.Items.Clear();
            //清空listNew
            listNew.Clear();
            string strSql = "select PLAN_NO " +
               " from wlw_dbc_oil_plan where ( IF_PLAN_END='1') ";
            if (!string.IsNullOrWhiteSpace(comboBox1.Text))
            {
                strSql += " and (GETOWNER like '%" + comboBox1.Text + "%' OR PLAN_NO like '%" + comboBox1.Text + "%') order by PLAN_NO desc";
            }
            DataTable dtCYJL = DataAccess.ExecuteDataTable(strSql);
            if (dtCYJL != null && dtCYJL.Rows.Count > 0)
            {
                for (int i = 0; i < dtCYJL.Rows.Count; i++)
                {
                    string PLAN_NO = dtCYJL.Rows[i]["PLAN_NO"].ToString();
                    listNew.Add(PLAN_NO);
                }

            }
            //combobox添加已经查到的关键词
            this.comboBox1.Items.AddRange(listNew.ToArray());
            //设置光标位置，否则光标位置始终保持在第一列，造成输入关键词的倒序排列
            this.comboBox1.SelectionStart = this.comboBox1.Text.Length;
            //保持鼠标指针原来状态，有时候鼠标指针会被下拉框覆盖，所以要进行一次设置。
            Cursor = Cursors.Default;
            //自动弹出下拉框
            //this.comboBox1.DroppedDown = true;
        }

        private void btnQuery_Click(object sender, EventArgs e)
        {
            
            if (comboBox1.Text.Trim() != "")
            {
                CheckData();
            }
            else
            {
                MessageBox.Show("请选择计划号！");
            }
        }
        //内容修改时进行模糊查询
        private void comboBox1_TextUpdate(object sender, EventArgs e)
        {
            //清空combobox
            this.comboBox1.Items.Clear();
            //清空listNew
            listNew.Clear();
            string strSql = "select PLAN_NO " +
               " from wlw_dbc_oil_plan where (IF_PLAN_END='1') ";
            if (!string.IsNullOrWhiteSpace(comboBox1.Text))
            {
                strSql += " and (GETOWNER like '%" + comboBox1.Text + "%'  OR PLAN_NO like '%" + comboBox1.Text + "%') order by PLAN_NO desc";
            }
            DataTable dtCYJL = DataAccess.ExecuteDataTable(strSql);
            if (dtCYJL != null && dtCYJL.Rows.Count > 0)
            {
                for (int i = 0; i < dtCYJL.Rows.Count; i++)
                {
                    string PLAN_NO = dtCYJL.Rows[i]["PLAN_NO"].ToString();
                    listNew.Add(PLAN_NO);
                }

            }
            //combobox添加已经查到的关键词
            this.comboBox1.Items.AddRange(listNew.ToArray());
            //设置光标位置，否则光标位置始终保持在第一列，造成输入关键词的倒序排列
            this.comboBox1.SelectionStart = this.comboBox1.Text.Length;
            //保持鼠标指针原来状态，有时候鼠标指针会被下拉框覆盖，所以要进行一次设置。
            Cursor = Cursors.Default;
            //自动弹出下拉框
            this.comboBox1.DroppedDown = true;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (comboBox1.Text.Trim() != "")
            {
                CheckAllData();
            }
            else 
            {
                MessageBox.Show("请选择计划号！");
            }
            
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            string jhh = comboBox1.Text.ToString().Trim();
            string idSQL = "Select getowner AS HZ ,DEPOT_NAME,to_char(dispatch_begin_time,'yyyy-mm-dd hh24:mi:ss') B_TIME,to_char(dispatch_end_time,'yyyy-mm-dd hh24:mi:ss') E_TIME from WLW_DBC_OIL_PLAN WHERE PLAN_NO='" + jhh + "'";
            DataTable dtID = DataAccess.ExecuteDataTable(idSQL);
            if (dtID != null && dtID.Rows.Count > 0)
            {
                string hz = dtID.Rows[0]["HZ"].ToString();
                string deopot_name = dtID.Rows[0]["DEPOT_NAME"].ToString();
                string b_time = dtID.Rows[0]["B_TIME"].ToString();
                string e_time = dtID.Rows[0]["E_TIME"].ToString();
                label2.Text = hz;
                label9.Text = deopot_name;
                label5.Text = b_time;
                label7.Text = e_time;
            }

        }

        
    }
}
